In [1]:
import os
import tqdm
import seaborn as sns
import scanpy as sc
import anndata
import squidpy as sq
import decoupler as dc
import matplotlib.pyplot as plt

import numpy as np
import pandas as pd

plt.rcdefaults()
sc.set_figure_params()
plt.rcParams['axes.grid'] = False
plt.rcParams['figure.figsize'] = (5,5)

from distance import calc_neighborhood,calc_intraneighborhood
from deconvolution import calc_leiden_on_deconv,get_dense_clusters,calc_utest
from run_decoupler import calc_all,get_activities,get_activities_per_group,get_geneset_pairs
from plot_funcs import *

all plot_funcs functions are available via

import plot_funcs
dir(plot_funcs)

load data

In [2]:
adata=sc.read_h5ad('/sc/arion/projects/HIMC/reference/single_cell_references/CRC_Merad_lab/visium.h5ad')
In [3]:
adata
Out[3]:
AnnData object with n_obs × n_vars = 19528 × 17943
    obs: 'in_tissue', 'array_row', 'array_col', 'pathologist_annotation', 'cell_num', 'singler', 'samples'
    uns: 'spatial'
    obsm: 'spatial'
In [4]:
deconv=pd.read_csv('/sc/arion/projects/HIMC/reference/single_cell_references/CRC_Merad_lab/visium_deconv.csv',index_col=0)
In [5]:
deconv.head(3)
Out[5]:
Tumor cE01 (Stem/TA-like) Tumor cE02 (Stem/TA-like/Immature Goblet) Tumor cE03 (Stem/TA-like prolif) Tumor cE04 (Enterocyte 1) Tumor cE05 (Enterocyte 2) Tumor cE06 (Immature Goblet) Tumor cE07 (Goblet/Enterocyte) Tumor cE08 (Goblet) Tumor cE09 (Best4) Tumor cE10 (Tuft) ... cTNI17 (gd-like T) cTNI18 (gd-like T PDCD1+) cTNI19 (gd-like T prolif) cTNI20 (PLZF+ T) cTNI21 (PLZF+ T prolif) cTNI22 (cTNI22) cTNI23 (NK CD16A+) cTNI24 (NK GZMK+) cTNI25 (NK XCL1+) cTNI26 (ILC3)
AAACAGAGCGACTCCT-1_MIME22_BIC18-A5_0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 ... 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
AAACAGGGTCTATATT-1_MIME22_BIC18-A5_0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 ... 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
AAACCCGAACGAAATC-1_MIME22_BIC18-A5_0 16.620792 2.728002 28.089024 0.645445 3.555189 0.026663 0.307238 0.416739 2.045653 1.645724 ... 0.049736 0.035469 0.083225 0.023816 0.117061 0.034603 0.029606 0.035814 0.056953 0.054548

3 rows × 98 columns

neighborhood

multiple samples

calculate neighborhood

In [6]:
ad=calc_neighborhood(adata,'pathologist_annotation','Tumor',5,'samples',
                    ['MIME22_BIC31-B4_0','MIME22_BIC31B6-V2_0'],True)
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
Running MIME22_BIC31-B4_0 sample
  0%|          | 0/6 [00:00<?, ?it/s]
Coordinates of neighbors are added in adata.obs['neighborhood_0']
Coordinates of neighbors are added in adata.obs['neighborhood_0_thin']
Cumulative neighborhood at the 100 micrometers distance is not calculated. Running it now.
 33%|███▎      | 2/6 [00:02<00:05,  1.40s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_1']
Coordinates of neighbors are added in adata.obs['neighborhood_1_thin']
Cumulative neighborhood at the 200 micrometers distance is not calculated. Running it now.
 50%|█████     | 3/6 [00:05<00:05,  1.96s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_2']
Coordinates of neighbors are added in adata.obs['neighborhood_2_thin']
Cumulative neighborhood at the 300 micrometers distance is not calculated. Running it now.
 67%|██████▋   | 4/6 [00:08<00:04,  2.31s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_3']
Coordinates of neighbors are added in adata.obs['neighborhood_3_thin']
Cumulative neighborhood at the 400 micrometers distance is not calculated. Running it now.
 83%|████████▎ | 5/6 [00:11<00:02,  2.57s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_4']
Coordinates of neighbors are added in adata.obs['neighborhood_4_thin']
Cumulative neighborhood at the 500 micrometers distance is not calculated. Running it now.
100%|██████████| 6/6 [00:14<00:00,  2.47s/it]
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
Coordinates of neighbors are added in adata.obs['neighborhood_5']
Coordinates of neighbors are added in adata.obs['neighborhood_5_thin']
Running MIME22_BIC31B6-V2_0 sample
  0%|          | 0/6 [00:00<?, ?it/s]
Coordinates of neighbors are added in adata.obs['neighborhood_0']
Coordinates of neighbors are added in adata.obs['neighborhood_0_thin']
Cumulative neighborhood at the 100 micrometers distance is not calculated. Running it now.
 33%|███▎      | 2/6 [00:03<00:06,  1.71s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_1']
Coordinates of neighbors are added in adata.obs['neighborhood_1_thin']
Cumulative neighborhood at the 200 micrometers distance is not calculated. Running it now.
 50%|█████     | 3/6 [00:06<00:07,  2.45s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_2']
Coordinates of neighbors are added in adata.obs['neighborhood_2_thin']
Cumulative neighborhood at the 300 micrometers distance is not calculated. Running it now.
 67%|██████▋   | 4/6 [00:10<00:05,  2.91s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_3']
Coordinates of neighbors are added in adata.obs['neighborhood_3_thin']
Cumulative neighborhood at the 400 micrometers distance is not calculated. Running it now.
 83%|████████▎ | 5/6 [00:14<00:03,  3.28s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_4']
Coordinates of neighbors are added in adata.obs['neighborhood_4_thin']
Cumulative neighborhood at the 500 micrometers distance is not calculated. Running it now.
100%|██████████| 6/6 [00:18<00:00,  3.16s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_5']
Coordinates of neighbors are added in adata.obs['neighborhood_5_thin']

plot neighborhood or any other .obs object for several samples using plot_spatial_scatter_n_neighborhood or plot_spatial_scatter for AnnData with one sample

In [7]:
plot_spatial_scatter_zeros(ad,'samples',None,
                             *['neighborhood_0_MIME22_BIC31-B4_0','neighborhood_1_MIME22_BIC31-B4_0','neighborhood_2_thin_MIME22_BIC31-B4_0',
                               'neighborhood_0_MIME22_BIC31B6-V2_0','neighborhood_1_MIME22_BIC31B6-V2_0','neighborhood_2_thin_MIME22_BIC31B6-V2_0',
                               'pathologist_annotation'])
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value

plot neghborhood composition for several samples using plot_neighborhood_composition_n_samples or plot_neighborhood_composition for AnnData with one sample

In [8]:
plot_neighborhood_composition_n_samples(ad,5,deconv,'samples',['MIME22_BIC31-B4_0','MIME22_BIC31B6-V2_0'],True)
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value

one sample

# how to choose one sample
samples=['MIME22_BIC21-A6_0']
adata_test=adata[adata.obs['samples'].isin(samples)]
adata_test.uns['spatial']={s:adata_test.uns['spatial'][s] for s,v in adata_test.uns['spatial'].items() if s in samples}
deconv_test=deconv.reindex(adata_test.obs_names)
In [9]:
samples=['MIME22_BIC21-A6_0']
adata_test=adata[adata.obs['samples'].isin(samples)]
adata_test.uns['spatial']={s:adata_test.uns['spatial'][s] for s,v in adata_test.uns['spatial'].items() if s in samples}
deconv_test=deconv.reindex(adata_test.obs_names)
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
In [10]:
adata_test=calc_neighborhood(adata_test,'pathologist_annotation','Tumor',1)
 50%|█████     | 1/2 [00:00<00:00,  2.98it/s]
Coordinates of neighbors are added in adata.obs['neighborhood_0']
Coordinates of neighbors are added in adata.obs['neighborhood_0_thin']
Cumulative neighborhood at the 100 micrometers distance is not calculated. Running it now.
100%|██████████| 2/2 [00:22<00:00, 11.34s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_1']
Coordinates of neighbors are added in adata.obs['neighborhood_1_thin']

In [11]:
plot_spatial_scatter(adata_test,'samples',None,
                     *['neighborhood_0','neighborhood_1',
                       'pathologist_annotation'])
In [12]:
plot_neighborhood_composition(adata_test,1,deconv,True)

intra-neighborhood

intra-neighbors are spots of nth layer of area of interest itself

multiple samples

In [13]:
n=5
s=['MIME22_BIC18-A5_0','MIME22_BIC18-A7_0']
ad=calc_intraneighborhood(adata,'pathologist_annotation','Tumor',n,'samples',s)
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
Running MIME22_BIC18-A5_0 sample
  0%|          | 0/6 [00:00<?, ?it/s]
Coordinates of neighbors are added in adata.obs['neighborhood_0_intra_MIME22_BIC18-A5_0']
 67%|██████▋   | 4/6 [00:00<00:00, 16.29it/s]
Coordinates of neighbors are added in adata.obs['neighborhood_1_intra_MIME22_BIC18-A5_0']
Coordinates of neighbors are added in adata.obs['neighborhood_2_intra_MIME22_BIC18-A5_0']
Coordinates of neighbors are added in adata.obs['neighborhood_3_intra_MIME22_BIC18-A5_0']
4th layer is empty. Previous one was already the core. Stopping the calculation.
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
Running MIME22_BIC18-A7_0 sample
  0%|          | 0/6 [00:00<?, ?it/s]
Coordinates of neighbors are added in adata.obs['neighborhood_0_intra_MIME22_BIC18-A7_0']
 33%|███▎      | 2/6 [00:00<00:00, 11.13it/s]
Coordinates of neighbors are added in adata.obs['neighborhood_1_intra_MIME22_BIC18-A7_0']
Coordinates of neighbors are added in adata.obs['neighborhood_2_intra_MIME22_BIC18-A7_0']
 83%|████████▎ | 5/6 [00:00<00:00, 22.00it/s]
Coordinates of neighbors are added in adata.obs['neighborhood_3_intra_MIME22_BIC18-A7_0']
Coordinates of neighbors are added in adata.obs['neighborhood_4_intra_MIME22_BIC18-A7_0']
5th layer is empty. Previous one was already the core. Stopping the calculation.

script will stop as soon as you reach "core"

In [14]:
plot_spatial_scatter_zeros(ad,'samples',s,
                           *['pathologist_annotation',
                             *[f'neighborhood_{i}_intra_MIME22_BIC18-A5_0' for i in range(4)],
                             *[f'neighborhood_{i}_intra_MIME22_BIC18-A7_0' for i in range(5)]
                             ])
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
In [15]:
plot_neighborhood_composition_n_samples(ad,5,deconv,'samples',s,False,True)
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value

one sample

and you can assess intra-neighborhood in one sample

In [16]:
samples=['MIME22_BIC21-A6_0']
adata_test=adata[adata.obs['samples'].isin(samples)]
adata_test.uns['spatial']={s:adata_test.uns['spatial'][s] for s,v in adata_test.uns['spatial'].items() if s in samples}
deconv_test=deconv.reindex(adata_test.obs_names)
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
In [17]:
adata_test=calc_intraneighborhood(adata_test,'pathologist_annotation','Tumor',3)
 25%|██▌       | 1/4 [00:00<00:00,  5.88it/s]
Coordinates of neighbors are added in adata.obs['neighborhood_0_intra']
 50%|█████     | 2/4 [00:14<00:17,  8.74s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_1_intra']
 75%|███████▌  | 3/4 [00:25<00:09,  9.62s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_2_intra']
100%|██████████| 4/4 [00:33<00:00,  8.35s/it]
Coordinates of neighbors are added in adata.obs['neighborhood_3_intra']

In [18]:
plot_spatial_scatter(adata_test,'samples',None,
                     *[*[f'neighborhood_{i}_intra' for i in range(4)],
                       'pathologist_annotation'])
In [19]:
plot_neighborhood_composition(adata_test,3,deconv,False,None,True)

deconvolution

right now leiden resolution is chosen by number of clusters (should be 9<=n<=11)

In [20]:
samples=['MIME22_BIC18-A5_0']
adata_test=adata[adata.obs['samples'].isin(samples)]
adata_test.uns['spatial']={s:adata_test.uns['spatial'][s] for s,v in adata_test.uns['spatial'].items() if s in samples}
deconv_test=deconv.reindex(adata_test.obs_names)
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
In [21]:
# adata_deconv=calc_leiden_on_deconv(adata,deconv,'samples',None,pre_computed_adata=False)
adata_deconv=calc_leiden_on_deconv(adata_test,deconv_test,None,None,pre_computed_adata=False)
/sc/arion/work/radkee01/notebooks/crc/deconvolution.py:42: FutureWarning: X.dtype being converted to np.float32 from float64. In the next version of anndata (0.9) conversion will not be automatic. Pass dtype explicitly to avoid this warning. Pass `AnnData(X, dtype=X.dtype, ...)` to get the future behavour.
  deconv_adata=anndata.AnnData(deconv)
PCA and UMAP are calculated for deconvoluted matrix
Optimal number of leiden clusters 9, res=0.6
Results for leiden clustering on deconvoluted matrix is saved in .obs['leiden_deconv']
PCA, UMAP are calculated for gene expression matrix
Optimal number of leiden clusters 8, res=1.0
Results for leiden clustering on gene expression matrix is saved in .obs['leiden']

plot results for any .obs keys -- here: leiden clusters on gene expression matrix/deconvolution and pathologist annotation on specified samples

In [22]:
toplot=['leiden_deconv_MIME22_BIC21-A6_0','leiden_MIME22_BIC21-A6_0',
        'leiden_deconv_MIME22_BIC31B6-V2_0','leiden_MIME22_BIC31B6-V2_0',
        'pathologist_annotation']
s=['MIME22_BIC31B6-V2_0','MIME22_BIC21-A6_0']
plot_spatial_scatter_zeros(adata_deconv,'samples',s,*toplot)
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value

one sample analysis

you can plot composition of whatever cluster whatever group you want. here it is a all clusters in leiden_deconv

In [25]:
plot_clusters_composition(adata_deconv,'leiden_deconv',deconv_test)
100%|██████████| 9/9 [00:08<00:00,  1.08it/s]

and then go deep and apply DBSCAN on whatever cluster you want

In [22]:
adata_deconv=get_dense_clusters(adata_deconv,'leiden_deconv','4')
Number of dense clusters = 5
Results for DBSCAN clustering is saved in .obs['denselabels']
In [23]:
toplot=['leiden_deconv',
        'denselabels',
        'pathologist_annotation']
plot_spatial_scatter(adata_deconv,None,samples,*toplot)
In [24]:
plot_clusters_composition(adata_deconv,'denselabels',deconv_test)
100%|██████████| 8/8 [00:06<00:00,  1.16it/s]

you can calculate U-statistics for one immune aggregate vs other for every cell subtype and report adjusted p-values

In [26]:
r=calc_utest(adata_test,deconv_test,'denselabels',mcorr=True)
In [27]:
r=r.astype(float).dropna(how='all',axis=1)
_,axs=plt.subplots(1,1,figsize=(.4*len(r.columns),2))
sns.heatmap(r,ax=axs,cmap='coolwarm')
Out[27]:
<AxesSubplot: >

also you can calculate cell-cell interaction inside clusters and compare top expressed receptor-ligand pairs

In [29]:
plot_rl_pairs(adata_deconv,'denselabels',True,True,genes_heatmap=['ANXA1','CLU'])
Loading CellPhoneDB
Calculating for dense labels. Excluding clusters `-1` and `1000`.
/sc/arion/work/radkee01/notebooks/crc/plot_funcs.py:370: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.axes.set_xticklabels(['|'.join(i) for i in rtmp.index],rotation=90)
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/plotting/_anndata.py:2414: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
  obs_tidy.index.value_counts(sort=False).iteritems()

decoupler

calculate progeny, dorothea and msigdb collections on all spots. sometimes it crashes with kernel restarting error -- it means that you need more RAM. 8 gb per node is ok

In [30]:
ad_dc=calc_all(adata,msigdb_collection=['kegg_pathways','reactome_pathways'],
               ora=True,precomp=False)
Normalizing, log-transforming, calculating PCA and UMAP.
Loading progeny
Running progeny
45 features of mat are empty, they will be removed.
Running mlm on mat with 19528 samples and 17898 targets for 14 sources.
100%|██████████| 2/2 [00:18<00:00,  9.35s/it]
Loading dorothea
Running dorothea
45 features of mat are empty, they will be removed.
Running mlm on mat with 19528 samples and 17898 targets for 297 sources.
100%|██████████| 2/2 [00:21<00:00, 10.84s/it]
Loading MSigDB
Extracting kegg_pathways
Running ora
45 features of mat are empty, they will be removed.
Running ora on mat with 19528 samples and 17898 targets for 185 sources.
100%|██████████| 19528/19528 [00:26<00:00, 734.83it/s]
Extracting reactome_pathways
Running ora
45 features of mat are empty, they will be removed.
Running ora on mat with 19528 samples and 17898 targets for 1632 sources.
100%|██████████| 19528/19528 [01:22<00:00, 235.93it/s]
/hpc/users/radkee01/.local/lib/python3.8/site-packages/pandas/core/internals/blocks.py:351: RuntimeWarning: divide by zero encountered in log10
  result = func(self.values, **kwargs)
In [31]:
gs=get_geneset_pairs(adata,['kegg_pathways','reactome_pathways'])
Loading progeny
Loading dorothea
Loading MSigDB

get activities and group activities for any decoupler calculation. group them and plot on UMAP

In [57]:
acts=get_activities(ad_dc,'reactome_pathways_ora_estimate')
acts_gr=get_activities_per_group(acts,'pathologist_annotation')
In [33]:
clustermap_of_activities(acts_gr.iloc[:,:30])
/usr/local/lib/python3.8/dist-packages/seaborn/matrix.py:1203: UserWarning: Tight layout not applied. The bottom and top margins cannot be made large enough to accommodate all axes decorations.
  self._figure.tight_layout(**tight_params)
In [68]:
plot_spatial_scatter_decoupler(acts,'samples',['MIME22_BIC18-A5_0','MIME22_BIC18-A7_0'],
                              *['pathologist_annotation',*['REACTOME_ABC_TRANSPORTER_DISORDERS','REACTOME_APOPTOSIS_INDUCED_DNA_FRAGMENTATION']])
MIME22_BIC18-A5_0
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value
MIME22_BIC18-A7_0
/usr/local/lib/python3.8/dist-packages/anndata/compat/_overloaded_dict.py:106: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.
  self.data[key] = value

one sample example

In [35]:
dc_df=pd.concat([ad_dc.obsm[i] for i in ad_dc.obsm if 'estimate' in i],axis=1).replace({np.inf:0})
In [36]:
adata_deconv.obsm['decoupler']=dc_df.reindex(adata_deconv.obs_names)
In [37]:
acts=get_activities(adata_deconv,'decoupler')
# acts_gr=get_activities_per_group(acts,'pathologist_annotation')

you can calculate most important features for any group in any .obs name

In [38]:
sc.tl.rank_genes_groups(acts,groupby='leiden_deconv')
WARNING: Default of the method has been changed to 't-test' from 't-test_overestim_var'
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/tools/_rank_genes_groups.py:420: RuntimeWarning: invalid value encountered in log2
  self.stats[group_name, 'logfoldchanges'] = np.log2(
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/tools/_rank_genes_groups.py:420: RuntimeWarning: invalid value encountered in log2
  self.stats[group_name, 'logfoldchanges'] = np.log2(
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/tools/_rank_genes_groups.py:420: RuntimeWarning: invalid value encountered in log2
  self.stats[group_name, 'logfoldchanges'] = np.log2(
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/tools/_rank_genes_groups.py:420: RuntimeWarning: invalid value encountered in log2
  self.stats[group_name, 'logfoldchanges'] = np.log2(
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/tools/_rank_genes_groups.py:420: RuntimeWarning: invalid value encountered in log2
  self.stats[group_name, 'logfoldchanges'] = np.log2(
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/tools/_rank_genes_groups.py:420: RuntimeWarning: invalid value encountered in log2
  self.stats[group_name, 'logfoldchanges'] = np.log2(
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/tools/_rank_genes_groups.py:420: RuntimeWarning: invalid value encountered in log2
  self.stats[group_name, 'logfoldchanges'] = np.log2(
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/tools/_rank_genes_groups.py:420: RuntimeWarning: invalid value encountered in log2
  self.stats[group_name, 'logfoldchanges'] = np.log2(
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/tools/_rank_genes_groups.py:420: RuntimeWarning: invalid value encountered in log2
  self.stats[group_name, 'logfoldchanges'] = np.log2(

for example first cluster in leiden clustering calculated on deconvolution is definitely enriched in myofibroblasts

In [39]:
gr='1'
masked=\
acts.uns['rank_genes_groups']['names'][gr][\
                                            acts.uns['rank_genes_groups']['pvals_adj'][gr]<0.05]
tohighlight=masked[:5]
print(tohighlight)
['SRF' 'REACTOME_TERMINAL_PATHWAY_OF_COMPLEMENT'
 'REACTOME_MUSCLE_CONTRACTION' 'KEGG_VASCULAR_SMOOTH_MUSCLE_CONTRACTION'
 'PBX3']
In [40]:
plot_spatial_scatter_decoupler(acts,None,None,
                               *['leiden_deconv',*tohighlight])

check expression of genes in specified geneset

In [41]:
plot_hm_gs(acts,adata_deconv,'SRF',gs)
/hpc/users/radkee01/.local/lib/python3.8/site-packages/scanpy/plotting/_anndata.py:2414: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
  obs_tidy.index.value_counts(sort=False).iteritems()
In [ ]: